package java6681.sort;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @Title: SortDemo6681
 * @Author Junichiro
 * @Description:TODO
 * @Date: 2020/12/24 0024 下午 10:18
 */
public class SortDemo6681 {
    public static void main(String[] args) {
        System.out.println("================按年龄排序================");
        Student[] students = {
                new Student("张三", 99.9, 21),
                new Student("赵四大", 88.8, 19),
                new Student("王兰花", 33.0, 38),
                new Student("矢的猛", 66.6, 44)
        };
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));

        System.out.println("==========按总分升序==============");
        Arrays.sort(students, new Comparator<Student>() {//新建匿名内部类，对学生成绩进行比较
            @Override
            public int compare(Student o1, Student o2) {
                Student s1 = (Student)o1;
                Student s2 = (Student)o2;
                return (int) (s1.getScore() - s2.getScore());
            }
        });
        System.out.println(Arrays.toString(students));
        System.out.println("==========按总分降序==============");
        Arrays.sort(students, new Comparator<Student>() {//新建匿名内部类，对学生成绩进行比较
            @Override
            public int compare(Student o1, Student o2) {
                Student s1 = (Student)o1;
                Student s2 = (Student)o2;
                return (int) (s2.getScore() - s1.getScore());
            }
        });
        System.out.println(Arrays.toString(students));
    }

   /* class SortByScoreAsc6681 implements Comparable<Student> {

        @Override
        public int compareTo(Student o) {
            Student s = (Student)o;
            return (int) (s.getScore() - o.getScore());
        }

    }

    class SortByScoreDesc6681 implements Comparable<Student> {

        @Override
        public int compareTo(Student o) {
            return 0;
        }
    }*/

}
